package com.lmj.vueadmin.controller;

import cn.hutool.core.map.MapUtil;
import com.lmj.vueadmin.common.lang.Result;
import com.lmj.vueadmin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @Autowired
    SysUserService userService;

    @GetMapping("/test")
    public Object test() {

        return userService.list();
    }

    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;
    @GetMapping("/test/pass")
    public Result passEncode() {
        // 密码加密
        String pass = bCryptPasswordEncoder.encode("888888");
        // 密码验证
        boolean matches = bCryptPasswordEncoder.matches("888888", pass);

        return Result.succ(MapUtil.builder()
                .put("pass", pass)
                .put("marches", matches)
                .build()
        );
    }
}
